package atguigu.cglib.demo3;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * 方法拦截
 * @author ex_yejing1
 *
 */
public class MyMethodInterceptor implements MethodInterceptor {
    
	private Object target;
    
    public MyMethodInterceptor(Object target) {
        this.target = target;
    }
    
    public Object intercept(//
    		Object o, //
    		Method method,//
            Object[] args, //
            MethodProxy methodProxy) //
        throws Throwable { //
    	
        Object result = null;
        
        // 获取方法执行的参数
        Float money = (Float)args[0];
        
        // 判断当前方法是不是销售
        if("saleProduce".equals(method.getName())){
            result = method.invoke(target, money*0.8f);
        }
        
        return result;
    }
}
